<template>
	<view>
		<view class="btns">
			<u-button size="small" @click="cancel">取消</u-button>
			<view class="title">设置昵称</view>
			<u-button size="small" type="success" @click="confirm">完成</u-button>
		</view>
		<uni-easyinput v-model="nickName" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickName: '',
				userId:''
			}
		},
		onLoad(options) {
			var info = JSON.parse(decodeURIComponent(options.info))
			console.log(info);
			this.nickName = info.name
			this.userId = info.userId
		},
		methods: {
			cancel(){
				uni.navigateBack()
			},
			async confirm(){
				if(this.nickName == ''){
					uni.showToast({
						title:'昵称不能为空',
						icon:'none'
					})
				}else{		
					// 修改用户昵称的请求
					const {data:res} =await this.$myRequest({
						url:'/userBefore/updateUser',
						method:'post',
						data:{
							name:this.nickName,
							userId:this.userId,
							}
					})
					if(res.code==20000){
						uni.showToast({
							title:'修改成功',
							icon:'success'
						})
						setTimeout(()=>{
						uni.navigateBack()
						},1500)
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btns {
		margin: 20rpx 0;
		width: 100%;
		height:60rpx;
		display: flex;
		justify-content: space-between;
		/deep/.u-button{
			width:20rpx;
			position:absolute;
			&:first-child{
				left: 20rpx;
			}
			&:last-child{
				right: 20rpx;
			}
		}
	}
	.title{
		margin: 0 auto;
	}
</style>
